package com.baitengsoft.patentservicemonitor.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期处理
 * 
 * @author KennyGu
 * @email 89335272@qq.com
 * @date 2017 下午12:53:33
 */
public class DateUtils {
    private  final  static int BEGIN_YEAR=1900;


	/** 时间格式(yyyy-MM-dd) */
	public final static String DATE_PATTERN = "yyyy-MM-dd";
	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
	
	public static String format(Date date) {
        return format(date, DATE_PATTERN);
    }

    public static String format(Date date, String pattern) {
        if(date != null){
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            return df.format(date);
        }
        return null;
    }

    public static int getYear(Date date){
	    Calendar c= Calendar.getInstance();
	    c.setTime(date);
	    return  c.get(Calendar.YEAR);
    }

    public static int getMonth(Date date){
        Calendar c= Calendar.getInstance();
        c.setTime(date);
        return  c.get(Calendar.MONTH)+1;
    }


    public static  String getMonthStr(Date date){
	    int month=DateUtils.getMonth(date);

	    if(month<10){
	        return  "0"+String.valueOf(month);
        }else{
	        return  String.valueOf(month);
        }
    }


}
